package com.itheima.tliasmanagement.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;

@Slf4j
//@Component
@Aspect
@Order(0)
public class MyAspect4 {

    @Pointcut("execution(* com.itheima.tliasmanagement.service.impl.DeptServiceImpl.*(..))")
    public void pc(){
    }

    @Before("pc()")
    public void before(JoinPoint jp) throws Throwable {
        Signature signature = jp.getSignature();
        String methodName = signature.getName();
        String className = signature.getDeclaringTypeName();
        log.info("before methodName:{} className:{}",methodName, className );
    }

    @Around("pc()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable{
        Signature signature = pjp.getSignature();
        String methodName = signature.getName();
        String className = signature.getDeclaringTypeName();
        Object[] args = pjp.getArgs();
        Object result = pjp.proceed();
        log.info("around methodName:{} className:{} args:{} return:{}",methodName, className,args,result);
        return result;
    }


}
